package com.svse.designPattern.structure.composite.composite;

import com.svse.designPattern.structure.composite.component.Component;

import java.util.ArrayList;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Date 2020/8/2 9:43
 */
public class Composite implements Component {
    private ArrayList<Component> children=new ArrayList<Component>();
    @Override
    public void add(Component c) {
        children.add(c);
    }

    @Override
    public void remove(Component c) {
        children.remove(c);
    }

    @Override
    public Component getChild(int i) {
        return children.get(i);
    }

    @Override
    public void operation() {
        for(Object obj:children)
        {
            ((Component)obj).operation();
        }
    }
}
